using UnityEngine;

public class MotoTilt : MonoBehaviour
{
	[SerializeField]
	private RCC_CarControllerV3 rccCar;

	public float maxTiltAngel = 45f;

	private float currentTiltAngel;

	private float currentSpeed;

	private float currentSteer;

	private float steerAng1;

	private float steerAng2;

	private void Start()
	{
		rccCar = GetComponentInParent<RCC_CarControllerV3>();
	}

	private void Update()
	{
		if (rccCar.enabled)
		{
			steerAng1 = Mathf.Lerp(steerAng1, rccCar.FrontRightWheelCollider.steerAngle, Time.deltaTime * 5f);
			steerAng2 = Mathf.Lerp(steerAng2, rccCar.steerAngle, Time.deltaTime * 5f);
			currentSpeed = Mathf.Clamp(rccCar.speed, 0f, 120f) / 120f;
			if (steerAng2 != 0f)
			{
				currentSteer = Mathf.Clamp(steerAng1, 0f - steerAng2, steerAng2) / steerAng2;
			}
			else
			{
				currentSteer = 0f;
			}
			currentTiltAngel = maxTiltAngel * currentSpeed * currentSteer;
			base.transform.localEulerAngles = new Vector3(0f, 0f, 0f - currentTiltAngel);
		}
	}
}
